import Vue from 'vue';
import App from './App.vue';
import router from './router';
import 'vant/lib/icon/local.css';
import '@/assets/scss/global.scss';
import '@/assets/scss/iconfont/iconfont.css';
import {authLoginByAccount} from '@/api/api'
import VueCountdown from '@chenfengyuan/vue-countdown';
import { setLocalStorage,getLocalStorage,getUrlParams } from '@/utils/local-storage';

import filters from '@/filter';

Vue.component(VueCountdown.name, VueCountdown);
Vue.use(filters);
import LuckDraw from 'vue-luck-draw'
Vue.use(LuckDraw)
import { Lazyload, Icon, Cell, CellGroup, loading, Button, Toast } from 'vant';
Vue.use(Icon);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(loading);
Vue.use(Button);
Vue.use(Toast);
Vue.use(Lazyload, {
  preLoad: 1.3,
  error: require('@/assets/images/goods_default.png'),
  loading: require('@/assets/images/goods_default.png'),
  attempt: 1,
  listenEvents: ['scroll'],
  lazyComponent: true
});
localStorage.removeItem("Authorization")

router.beforeEach((to, from, next) => {
 
  let token = getLocalStorage('Authorization')
  if(token.Authorization){
    next()
  }else{
    // 13134231821
    // getUrlParams('phone')
    authLoginByAccount({ password: '123456', username: getUrlParams('phone') }).then(res=>{
      setLocalStorage({
        Authorization: res.data.data.token,
        avatar: res.data.data.userInfo.avatarUrl,
        nickName: res.data.data.userInfo.nickName
      });
      next()
    })
  }
})

Vue.config.productionTip = false;

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');
